package kr.couponplay.android.activity.search;

import java.util.List;

import kr.couponplay.android.domain.deal.Deal;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class SearchListAdapter extends ArrayAdapter<Deal> {
	private Context mContext;
	private int mResource;
	private List<Deal> deals;
	private LayoutInflater mInflater;

	public SearchListAdapter(Context context, int layoutResource, List<Deal> deals) {
		super(context, layoutResource, deals);
		this.mContext = context;
		this.mResource = layoutResource;
		this.deals = deals;
		this.mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Deal deal = deals.get(position);

		if (convertView == null) {
			convertView = mInflater.inflate(mResource, parent, false);
		}

//		if (item != null) {
//			TextView providerCode = (TextView) convertView.findViewById(R.id.message_providerCode);
//			TextView receivedDate = (TextView) convertView.findViewById(R.id.message_receivedDate);
//			TextView message = (TextView) convertView.findViewById(R.id.message_text);
//			
//			providerCode.setText(item.getProviderCode().getDisplay());
//			receivedDate.setText(DisplayUtils.dateFormat(item.getReceivedDate(), "yyyy-MM-dd HH:mm"));
//			message.setText((item.getMessage().length() > 200)? item.getMessage().substring(0, 200) + ".." : item.getMessage());
//			
//			MessageOnClickListener messageOnClickListener = new MessageOnClickListener(mContext, this, position);
//			message.setOnClickListener(messageOnClickListener);
//		}
		return convertView;
	}
	
	public Deal getItem(int position) {
		return deals.get(position);
	}
	
	public int getItemSize() {
		return deals.size();
	}
}
